<?php

    header('Content-Type: text/javascript');
    header('Cache-Control: no-cache');
    header('Pragma: no-cache');

    require_once 'mysql.php';

    $link = connect();
    mysql_select_db("c2cv2",$link);


    $query =
            "SELECT
                    person.id,
                    person.name,
                    role.party,
                    wnom_scores.score as newX,
                    verb_scores.score as newY
            FROM
                    person,
                    role,
                    verb_scores,
                    wnom_scores
            WHERE
                    person.id = role.person_id AND
                    person.id = verb_scores.person_id AND
                    person.id = wnom_scores.person_id AND
                    wnom_log.chamber = " . $_GET['chamber'] . " AND
                    wnom_log.id = verb_scores.log_id AND
                    wnom_log.start = " . $_GET['start'] . " AND
                    wnom_log.end = " . $_GET['end'] . " AND
                    verb_log.chamber = " . $_GET['chamber'] . " AND
                    verb_log.id = verb_scores.log_id AND
                    verb_log.start = " . $_GET['start'] . " AND
                    verb_log.end = " . $_GET['end'] . "
            ORDER BY person_id ASC;";

    //echo $query;

    $rs = mysql_query($query) or die("MySQL error: " . mysql_error());


    $json =  '[';

    $session = $_GET['session'];
    $chamber = $_GET['chamber'];


    while($o = mysql_fetch_array($rs,MYSQL_ASSOC)) {
    //	echo "<pre>" . print_r($o) . "</pre>";
        $id = $o['person.id'];
        $name = $o['person.name'];
        $party = $o['role.party'];
        $x = $o['newX'];
        $y = $o['newY'];

        $json .= '{';

        $json .= "\"id\":\"$id\",";
        $json .= "\"name\":\"$name\",";
        $json .= "\"party\":\"$party\",";
        $json .= "\"newX\":\"$x\",";
        $json .= "\"newY\":\"$y\"";

        $json .= '},';

    }
    $json = substr($json,0,strlen($json)-1);

    disconnect($link);

    $json .= ']';

    echo $json;

?>